﻿using System;
using System.Runtime.InteropServices;

namespace TestCenter.Classes
{
    class WinApi
    {
        public enum HookType : int
        {
            WH_JOURNALRECORD = 0,
            WH_JOURNALPLAYBACK = 1,
            WH_KEYBOARD = 2,
            WH_GETMESSAGE = 3,
            WH_CALLWNDPROC = 4,
            WH_CBT = 5,
            WH_SYSMSGFILTER = 6,
            WH_MOUSE = 7,
            WH_HARDWARE = 8,
            WH_DEBUG = 9,
            WH_SHELL = 10,
            WH_FOREGROUNDIDLE = 11,
            WH_CALLWNDPROCRET = 12,
            WH_KEYBOARD_LL = 13,
            WH_MOUSE_LL = 14
        }

        public delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll")]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

        public const UInt32 SWP_NOSIZE = 0x0001;
        public const UInt32 SWP_NOMOVE = 0x0002;
        public const UInt32 SWP_NOZORDER = 0x0004;
        public const UInt32 SWP_NOREDRAW = 0x0008;
        public const UInt32 SWP_NOACTIVATE = 0x0010;
        public const UInt32 SWP_FRAMECHANGED = 0x0020;  /* The frame changed: send WM_NCCALCSIZE */
        public const UInt32 SWP_SHOWWINDOW = 0x0040;
        public const UInt32 SWP_HIDEWINDOW = 0x0080;
        public const UInt32 SWP_NOCOPYBITS = 0x0100;
        public const UInt32 SWP_NOOWNERZORDER = 0x0200;  /* Don't do owner Z ordering */
        public const UInt32 SWP_NOSENDCHANGING = 0x0400;  /* Don't send WM_WINDOWPOSCHANGING */

        [DllImport("user32.dll")]
        public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("user32.dll")]
        public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        // For Windows Mobile, replace user32.dll with coredll.dll
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        // Find window by Caption only. Note you must pass IntPtr.Zero as the first parameter.
        // Also consider whether you're being lazy or not.
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        public static extern IntPtr FindWindowByCaption(IntPtr zeroOnly, string lpWindowName);

        [DllImport("user32")]
        public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);

        public const Int32 GWL_ID = (-12);
        public const Int32 GWL_STYLE = (-16);
        public const Int32 GWL_EXSTYLE = (-20);

        // Window Styles 
        public static readonly UInt32 WS_OVERLAPPED = 0;
        public static readonly UInt32 WS_POPUP = 0x80000000;
        public static readonly UInt32 WS_CHILD = 0x40000000;
        public static readonly UInt32 WS_MINIMIZE = 0x20000000;
        public static readonly UInt32 WS_VISIBLE = 0x10000000;
        public static readonly UInt32 WS_DISABLED = 0x8000000;
        public static readonly UInt32 WS_CLIPSIBLINGS = 0x4000000;
        public static readonly UInt32 WS_CLIPCHILDREN = 0x2000000;
        public static readonly UInt32 WS_MAXIMIZE = 0x1000000;
        public static readonly UInt32 WS_CAPTION = 0xC00000;      // WS_BORDER or WS_DLGFRAME  
        public static readonly UInt32 WS_BORDER = 0x800000;
        public static readonly UInt32 WS_DLGFRAME = 0x400000;
        public static readonly UInt32 WS_VSCROLL = 0x200000;
        public static readonly UInt32 WS_HSCROLL = 0x100000;
        public static readonly UInt32 WS_SYSMENU = 0x80000;
        public static readonly UInt32 WS_THICKFRAME = 0x40000;
        public static readonly UInt32 WS_GROUP = 0x20000;
        public static readonly UInt32 WS_TABSTOP = 0x10000;
        public static readonly UInt32 WS_MINIMIZEBOX = 0x20000;
        public static readonly UInt32 WS_MAXIMIZEBOX = 0x10000;
        public static readonly UInt32 WS_TILED = WS_OVERLAPPED;
        public static readonly UInt32 WS_ICONIC = WS_MINIMIZE;
        public static readonly UInt32 WS_SIZEBOX = WS_THICKFRAME;

        // Extended Window Styles 
        public static readonly UInt32 WS_EX_DLGMODALFRAME = 0x0001;
        public static readonly UInt32 WS_EX_NOPARENTNOTIFY = 0x0004;
        public static readonly UInt32 WS_EX_TOPMOST = 0x0008;
        public static readonly UInt32 WS_EX_ACCEPTFILES = 0x0010;
        public static readonly UInt32 WS_EX_TRANSPARENT = 0x0020;
        public static readonly UInt32 WS_EX_MDICHILD = 0x0040;
        public static readonly UInt32 WS_EX_TOOLWINDOW = 0x0080;
        public static readonly UInt32 WS_EX_WINDOWEDGE = 0x0100;
        public static readonly UInt32 WS_EX_CLIENTEDGE = 0x0200;
        public static readonly UInt32 WS_EX_CONTEXTHELP = 0x0400;
        public static readonly UInt32 WS_EX_RIGHT = 0x1000;
        public static readonly UInt32 WS_EX_LEFT = 0x0000;
        public static readonly UInt32 WS_EX_RTLREADING = 0x2000;
        public static readonly UInt32 WS_EX_LTRREADING = 0x0000;
        public static readonly UInt32 WS_EX_LEFTSCROLLBAR = 0x4000;
        public static readonly UInt32 WS_EX_RIGHTSCROLLBAR = 0x0000;
        public static readonly UInt32 WS_EX_CONTROLPARENT = 0x10000;
        public static readonly UInt32 WS_EX_STATICEDGE = 0x20000;
        public static readonly UInt32 WS_EX_APPWINDOW = 0x40000;
        public static readonly UInt32 WS_EX_OVERLAPPEDWINDOW = (WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE);
        public static readonly UInt32 WS_EX_PALETTEWINDOW = (WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST);
        public static readonly UInt32 WS_EX_LAYERED = 0x00080000;
        public static readonly UInt32 WS_EX_NOINHERITLAYOUT = 0x00100000; // Disable inheritence of mirroring by children
        public static readonly UInt32 WS_EX_LAYOUTRTL = 0x00400000; // Right to left mirroring
        public static readonly UInt32 WS_EX_COMPOSITED = 0x02000000;
        public static readonly UInt32 WS_EX_NOACTIVATE = 0x08000000;
    }
}
